package org.tim.controller;

/**
 *
 * @author Tim Fennis
 *
 */
public class PollData {

	public static final boolean LEFT_ANALOG = true;
	public static final boolean RIGHT_ANALOG = false;

	private final boolean stick;

	private float v = 0.0f;
	private float h = 0.0f;

	private static float leftvdef = 0.0f;
	private static float lefthdef = 0.0f;
	private static float rightvdef = 0.0f;
	private static float righthdef = 0.0f;

	public PollData ( float v , float h , boolean stick ) {
		this.stick = stick;
		this.v = v;
		this.h = h;
	}

	public float getv ( ) {
		return v;
	}

	public float geth ( ) {
		return h;
	}

	public float getvclean( ) {
		if ( stick == RIGHT_ANALOG ) {
			return v - rightvdef;
		} else {
			return v - leftvdef;
		}
	}

	public float gethclean( ) {
		if ( stick == RIGHT_ANALOG ) {
			return h - righthdef;
		} else {
			return h - lefthdef;
		}
	}

	public float getvdef ( boolean stick ) {
		if ( stick == RIGHT_ANALOG ) {
			return rightvdef;
		} else {
			return leftvdef;
		}
	}

	public float gethdef ( boolean stick ) {
		if ( stick == RIGHT_ANALOG ) {
			return righthdef;
		} else {
			return lefthdef;
		}
	}

	public boolean getStick() {
		return stick;
	}

	public static void defaultValues( float lv , float lh , float rv , float rh ) {
		leftvdef = lv;
		lefthdef = lh;
		rightvdef = rv;
		righthdef = rh;
	}

	public String toString ( ) {
		String s  = "AnalogEvent ae for [" + (stick == RIGHT_ANALOG ? "right-stick" : "left-stick") + "]\n";

		// V data
		s += "vdef\t" + (stick == RIGHT_ANALOG ? rightvdef : leftvdef ) + "\n";
		s += "vval\t" + v + "\n";

		// H data
		s += "hdef\t" + (stick == RIGHT_ANALOG ? righthdef : lefthdef ) + "\n";
		s += "hval\t" + h + "\n";

		// Clean values
		s += "[" + getvclean() + "][" + gethclean() + "]\n";
		return s;
	}
}
